/**
 * 用户相关API
 */
import api from './index'
import { withApiBase } from '@/config/runtime'

const requestJson = (url) => fetch(url).then((res) => res.json())

export const userAPI = {
  // 账号密码登录
  login: (phone, password) => {
    const qs = new URLSearchParams({
      phone,
      password_hash: password
    }).toString()
    return requestJson(withApiBase(`/user/login?${qs}`))
  },
  
  // 获取钉钉登录URL
  getDingTalkUrl: () => requestJson(withApiBase('/user/baidu')),
  
  // 检查是否为管理员
  isAdmin: () => api.get('/user/is_admin'),
  
  // 获取当前用户信息
  getCurrentUser: () => api.get('/user/me'),
}

